/* eslint-disable @typescript-eslint/no-explicit-any */
/*
 *  Copyright 2021 Collate
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *  http://www.apache.org/licenses/LICENSE-2.0
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

 /**
 * This schema defines the Pipeline entity. A pipeline enables the flow of data from source
 * to destination through a series of processing steps. ETL is a type of pipeline where the
 * series of steps Extract, Transform and Load the data.
 */
export interface Pipeline {
    /**
     * Change that lead to this version of the entity.
     */
    changeDescription?: ChangeDescription;
    /**
     * Concurrency of the Pipeline.
     */
    concurrency?: number;
    /**
     * Domain the Pipeline belongs to. When not set, the pipeline inherits the domain from the
     * Pipeline service it belongs to.
     */
    dataAssetDir?: EntityReference;
    /**
     * List of data products this entity is part of.
     */
    dataProducts?: EntityReference[];
    /**
     * When `true` indicates the entity has been soft deleted.
     */
    deleted?: boolean;
    /**
     * Description of this Pipeline.
     */
    description?: string;
    /**
     * Display Name that identifies this Pipeline. It could be title or label from the source
     * services.
     */
    displayName?: string;
    /**
     * Domain the Pipeline belongs to. When not set, the pipeline inherits the domain from the
     * Pipeline service it belongs to.
     */
    domain?: EntityReference;
    /**
     * Entity extension data with custom attributes added to the entity.
     */
    extension?: any;
    /**
     * Followers of this Pipeline.
     */
    followers?: EntityReference[];
    /**
     * A unique name that identifies a pipeline in the format 'ServiceName.PipelineName'.
     */
    fullyQualifiedName?: string;
    /**
     * Link to the resource corresponding to this entity.
     */
    href?: string;
    /**
     * Unique identifier that identifies a pipeline instance.
     */
    id: string;
    /**
     * Life Cycle properties of the entity
     */
    lifeCycle?: LifeCycle;
    /**
     * Name that identifies this pipeline instance uniquely.
     */
    name: string;
    /**
     * Owner of this pipeline.
     */
    owner?: EntityReference;
    /**
     * Pipeline Code Location.
     */
    pipelineLocation?: string;
    /**
     * Latest Pipeline Status.
     */
    pipelineStatus?: PipelineStatus;
    /**
     * Scheduler Interval for the pipeline in cron format.
     */
    scheduleInterval?: string;
    /**
     * Link to service where this pipeline is hosted in.
     */
    service: EntityReference;
    /**
     * Service type where this pipeline is hosted in.
     */
    serviceType?: PipelineServiceType;
    /**
     * Source hash of the entity
     */
    sourceHash?: string;
    /**
     * Pipeline  URL to visit/manage. This URL points to respective pipeline service UI.
     */
    sourceUrl?: string;
    /**
     * Start date of the workflow.
     */
    startDate?: Date;
    /**
     * Tags for this Pipeline.
     */
    tags?: TagLabel[];
    /**
     * All the tasks that are part of pipeline.
     */
    tasks?: Task[];
    /**
     * Last update time corresponding to the new version of the entity in Unix epoch time
     * milliseconds.
     */
    updatedAt?: number;
    /**
     * User who made the update.
     */
    updatedBy?: string;
    /**
     * Metadata version of the entity.
     */
    version?: number;
    votes?:   Votes;
}

/**
 * Change that lead to this version of the entity.
 *
 * Description of the change.
 */
export interface ChangeDescription {
    /**
     * Names of fields added during the version changes.
     */
    fieldsAdded?: FieldChange[];
    /**
     * Fields deleted during the version changes with old value before deleted.
     */
    fieldsDeleted?: FieldChange[];
    /**
     * Fields modified during the version changes with old and new values.
     */
    fieldsUpdated?: FieldChange[];
    /**
     * When a change did not result in change, this could be same as the current version.
     */
    previousVersion?: number;
}

export interface FieldChange {
    /**
     * Name of the entity field that changed.
     */
    name?: string;
    /**
     * New value of the field. Note that this is a JSON string and use the corresponding field
     * type to deserialize it.
     */
    newValue?: any;
    /**
     * Previous value of the field. Note that this is a JSON string and use the corresponding
     * field type to deserialize it.
     */
    oldValue?: any;
}

/**
 * Domain the Pipeline belongs to. When not set, the pipeline inherits the domain from the
 * Pipeline service it belongs to.
 *
 * This schema defines the EntityReference type used for referencing an entity.
 * EntityReference is used for capturing relationships from one entity to another. For
 * example, a table has an attribute called database of type EntityReference that captures
 * the relationship of a table `belongs to a` database.
 *
 * List of data products this entity is part of.
 *
 *
 * 此模式定义了用于引用实体的EntityReferenceList类型，EntityReference用于捕获从一个实体到另一个实体的关系。例如，表具有一个名为数据库的EntityReference类型的属性，该属性捕获表“属于”数据库的关系。
 *
 * 创建、更新或访问数据资产的用户、流水线或查询
 *
 * Owner of this pipeline.
 *
 * Link to service where this pipeline is hosted in.
 *
 * Owner of this task.
 */
export interface EntityReference {
    /**
     * If true the entity referred to has been soft-deleted.
     */
    deleted?: boolean;
    /**
     * Optional description of entity.
     */
    description?: string;
    /**
     * Display Name that identifies this entity.
     */
    displayName?: string;
    /**
     * Fully qualified name of the entity instance. For entities such as tables, databases
     * fullyQualifiedName is returned in this field. For entities that don't have name hierarchy
     * such as `user` and `team` this will be same as the `name` field.
     */
    fullyQualifiedName?: string;
    /**
     * Link to the entity resource.
     */
    href?: string;
    /**
     * Unique identifier that identifies an entity instance.
     */
    id: string;
    /**
     * If true the relationship indicated by this entity reference is inherited from the parent
     * entity.
     */
    inherited?: boolean;
    /**
     * Name of the entity instance.
     */
    name?: string;
    /**
     * Entity type/class name - Examples: `database`, `table`, `metrics`, `databaseService`,
     * `dashboardService`...
     */
    type: string;
}

/**
 * Life Cycle properties of the entity
 *
 * 此模式定义生命周期属性
 */
export interface LifeCycle {
    /**
     * 关于数据资产访问方面的访问详细信息
     */
    accessed?: AccessDetails;
    /**
     * 关于数据资产创建方面的访问详细信息
     */
    created?: AccessDetails;
    /**
     * 关于数据资产更新方面的访问详细信息
     */
    updated?: AccessDetails;
}

/**
 * 关于数据资产访问方面的访问详细信息
 *
 * 实体的访问详细信息
 *
 * 关于数据资产创建方面的访问详细信息
 *
 * 关于数据资产更新方面的访问详细信息
 */
export interface AccessDetails {
    /**
     * 创建、更新或访问数据资产的用户、流水线或查询
     */
    accessedBy?: EntityReference;
    /**
     * 访问数据资产的任何未在 OpenMetadata 中捕获的过程
     */
    accessedByAProcess?: string;
    /**
     * 数据资产创建、更新或读取的时间戳
     */
    timestamp: number;
}

/**
 * Latest Pipeline Status.
 *
 * Series of pipeline executions, its status and task status.
 */
export interface PipelineStatus {
    /**
     * Status at a specific execution date.
     */
    executionStatus: StatusType;
    /**
     * Series of task executions and its status.
     */
    taskStatus?: TaskStatus[];
    /**
     * Timestamp where the job was executed.
     */
    timestamp: number;
}

/**
 * Status at a specific execution date.
 *
 * Enum defining the possible Status.
 */
export enum StatusType {
    Failed = "Failed",
    Pending = "Pending",
    Skipped = "Skipped",
    Successful = "Successful",
}

/**
 * This schema defines a time series of the status of a Pipeline or Task.
 */
export interface TaskStatus {
    /**
     * Task end time
     */
    endTime?: number;
    /**
     * Status at a specific execution date.
     */
    executionStatus: StatusType;
    /**
     * Task end time
     */
    logLink?: string;
    /**
     * Name of the Task.
     */
    name: string;
    /**
     * Task start time
     */
    startTime?: number;
}

/**
 * Service type where this pipeline is hosted in.
 *
 * Type of pipeline service - Airflow or Prefect.
 */
export enum PipelineServiceType {
    Airbyte = "Airbyte",
    Airflow = "Airflow",
    CustomPipeline = "CustomPipeline",
    Dagster = "Dagster",
    DatabricksPipeline = "DatabricksPipeline",
    DomoPipeline = "DomoPipeline",
    Fivetran = "Fivetran",
    GluePipeline = "GluePipeline",
    KafkaConnect = "KafkaConnect",
    Nifi = "Nifi",
    OpenLineage = "OpenLineage",
    Spark = "Spark",
    Spline = "Spline",
}

/**
 * 此模式定义了用于使用标签标记实体的标签类型
 */
export interface TagLabel {
    /**
     * 标签标签的描述
     */
    description?: string;
    /**
     * 标识此标签的显示名称
     */
    displayName?: string;
    /**
     * 到标签资源的链接
     */
    href?: string;
    /**
     *
     * 标签类型描述标签标签是如何应用的，'Manual'表示标签标签是由人员应用的。'Derived'表示使用关联的标签关系导出了标签标签（有关详细信息，请参见Classification.json）。'Propagated`表示标签标签是根据血统从上游传播的。'Automated'在使用工具确定标签标签时使用。
     */
    labelType: LabelType;
    /**
     * 标签或词汇术语的名称
     */
    name?: string;
    /**
     * 标签来自标签还是词汇表
     */
    source: TagSource;
    /**
     * 'Suggested'状态在用户或工具建议标签标签时使用。实体的所有者必须在将其标记为'Confirmed'之前确认建议的标签
     */
    state:  State;
    style?: Style;
    tagFQN: string;
}

/**
 *
 * 标签类型描述标签标签是如何应用的，'Manual'表示标签标签是由人员应用的。'Derived'表示使用关联的标签关系导出了标签标签（有关详细信息，请参见Classification.json）。'Propagated`表示标签标签是根据血统从上游传播的。'Automated'在使用工具确定标签标签时使用。
 */
export enum LabelType {
    Automated = "Automated",
    Derived = "Derived",
    Manual = "Manual",
    Propagated = "Propagated",
}

/**
 * 标签来自标签还是词汇表
 */
export enum TagSource {
    Classification = "Classification",
    Glossary = "Glossary",
}

/**
 * 'Suggested'状态在用户或工具建议标签标签时使用。实体的所有者必须在将其标记为'Confirmed'之前确认建议的标签
 */
export enum State {
    Confirmed = "Confirmed",
    Suggested = "Suggested",
}

/**
 * UI Style is used to associate a color code and/or icon to entity to customize the look of
 * that entity in UI.
 */
export interface Style {
    /**
     * Hex Color Code to mark an entity such as GlossaryTerm, Tag, Domain or Data Product.
     */
    color?: string;
    /**
     * An icon to associate with GlossaryTerm, Tag, Domain or Data Product.
     */
    iconURL?: string;
}

export interface Task {
    /**
     * Description of this Task.
     */
    description?: string;
    /**
     * Display Name that identifies this Task. It could be title or label from the pipeline
     * services.
     */
    displayName?: string;
    /**
     * All the tasks that are downstream of this task.
     */
    downstreamTasks?: string[];
    /**
     * end date for the task.
     */
    endDate?: string;
    /**
     * A unique name that identifies a pipeline in the format
     * 'ServiceName.PipelineName.TaskName'.
     */
    fullyQualifiedName?: string;
    /**
     * Name that identifies this task instance uniquely.
     */
    name: string;
    /**
     * Owner of this task.
     */
    owner?: EntityReference;
    /**
     * Task URL to visit/manage. This URL points to respective pipeline service UI.
     */
    sourceUrl?: string;
    /**
     * start date for the task.
     */
    startDate?: string;
    /**
     * Tags for this task.
     */
    tags?: TagLabel[];
    /**
     * SQL used in the task. Can be used to determine the lineage.
     */
    taskSQL?: string;
    /**
     * Type of the Task. Usually refers to the class it implements.
     */
    taskType?: string;
}

/**
 * 此模式定义数据资产的投票
 */
export interface Votes {
    /**
     * 所有给予踩的用户列表
     */
    downVoters?: EntityReference[];
    /**
     * 实体的总踩数
     */
    downVotes?: number;
    /**
     * 所有给予赞的用户列表
     */
    upVoters?: EntityReference[];
    /**
     * 实体的总赞数
     */
    upVotes?: number;
}
